package com.xbongbong.pay.platform.wechatpay.utils;

import java.util.HashMap;
import java.util.Map;
/**
 * 微信支付 head工具
 * @author 魏荣杰
 * @date 2021/1/14 11:15
 * @since
 * @version
 */
public class WeChatPayHeadUtil {

    private static final String OS = System.getProperty("os.name") + "/" + System.getProperty("os.version");
    private static final String VERSION = System.getProperty("java.version");

    public static Map<String, String> getBaseHeaders(String authorization) {
        String userAgent = String.format(
                "WeChatPay-HttpClient/%s (%s) Java/%s",
                WeChatPayApi.class.getPackage().getImplementationVersion(),
                OS,
                VERSION == null ? "Unknown" : VERSION);

        Map<String, String> headers = new HashMap<>(5);
        headers.put("Accept", "application/json");
        headers.put("Authorization", authorization);
        headers.put("User-Agent", userAgent);
        return headers;
    }

    public static Map<String, String> getHeaders(String authorization, String serialNumber) {
        Map<String, String> headers = getBaseHeaders(authorization);
        headers.put("Content-Type", "application/json");
        if (serialNumber != null) {
            headers.put("Wechatpay-Serial", serialNumber);
        }
        return headers;
    }

    /**
     * Description: 上传header
     * @param authorization
     * @param serialNumber
     * @return java.util.Map<java.lang.String,java.lang.String>
     * @throws
     * @author 魏荣杰
     * @date 2021/1/14 11:17
     * @since
     */
    public static Map<String, String> getUploadHeaders(String authorization, String serialNumber) {
        Map<String, String> headers = getBaseHeaders(authorization);
        headers.put("Content-Type", "multipart/form-data;boundary=\"boundary\"");
        if (serialNumber != null) {
            headers.put("Wechatpay-Serial", serialNumber);
        }
        return headers;
    }

}
